package com.yanftch.stopcoding.test

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.yanftch.stopcoding.common.network.ImageLoader
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import javax.swing.ImageIcon
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.SwingUtilities
import kotlin.coroutines.EmptyCoroutineContext

class TestAction: AnAction() {
    override fun actionPerformed(p0: AnActionEvent) {
        val scope = CoroutineScope(EmptyCoroutineContext)
        scope.launch {
            val loader = ImageLoader()
            val result = loader.loadImage("https://imgapi.cn/api.php")
            SwingUtilities.invokeLater {
                // 创建一个 JFrame
                val frame = JFrame("Two Centered Labels Example")
                frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
                frame.setSize(400, 200)
                val label = JLabel()
                label.icon = ImageIcon(result?.image)
                frame.add(label)

                frame.isVisible = true
            }
        }
    }
}